package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.CpJydStatus;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.quality.QualityFinishedExamine;
import com.ruoyi.system.mapper.QualityFinishedExamineMapper;
import com.ruoyi.system.service.IQualityFinishedExamineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author GE-LV5
 * @create 2023/2/26 15:22
 * 成品检验单
 */
@Service
public class QualityFinishedExamineServiceImpl extends ServiceImpl<QualityFinishedExamineMapper, QualityFinishedExamine> implements IQualityFinishedExamineService {

    @Autowired
    QualityFinishedExamineMapper qualityFinishedExamineMapper;

    @Override
    public QualityFinishedExamine selectSetAreaById(Long id) {
        return qualityFinishedExamineMapper.selectSetAreaById(id);
    }

    /**
     * 查看成品检验单
     *
     * @param quality
     * @return
     */
    @Override
    public List<QualityFinishedExamine> selectQualityFinishedExamineList(QualityFinishedExamine quality) {
        return qualityFinishedExamineMapper.selectQualityFinishedExamine(quality);
    }

    /**
     * 删除成品检验单
     *
     * @param id
     * @return
     */
    @Override
    public int deleteQualityFinishedExamineById(Long id) {
        if (CpJydStatus.INSPECTION_CENTER.equals("1")) {
            throw new CustomException("成品正在检验中不能删除！");
        }
        return qualityFinishedExamineMapper.deleteQualityFinishedExamineById(id);
    }


    /**
     * 添加成品检验单
     *
     * @param quality 成品检验单
     * @return
     */
    @Override
    @Transactional
    public int insertQualityFinishedExamine(QualityFinishedExamine quality) {
        if (StringUtils.isNull(quality)) {
            throw new CustomException("添加失败！");
        }
        quality.setCreateTime(DateUtils.getNowDate());
        quality.setCreateBy(SecurityUtils.getUsername());
        quality.setUpdateBy(SecurityUtils.getUsername());
        quality.setUpdateTime(DateUtils.getNowDate());
        return qualityFinishedExamineMapper.insertQualityFinishedExamine(quality);
    }


}
